import {ModalForm, ProFormGroup, ProFormText, ProFormSelect} from '@ant-design/pro-form'
import {updateHospitalSet} from '@/services/hospital-set/api'

interface HospitalSetModalFormProps {
  initialValues: Partial<API.HospitalSetItem>|undefined;
  createModalVisible: any;
  handleModalVisible: any;
  actionRef: any;
}

const HospitalSetModalForm: React.FC<HospitalSetModalFormProps>
  = ({
       initialValues,
       createModalVisible,
       handleModalVisible,
       actionRef
     }) => {
  if (createModalVisible) {
    return <ModalForm
      title="新建医院设置"
      initialValues={initialValues||{}}
      visible={createModalVisible}
      onVisibleChange={handleModalVisible}
      onFinish={async (value) => {
        // 新增和修改合在一起
        const success = await updateHospitalSet(value as API.HospitalSetItem, value.id ? 'PUT' : 'POST');

        if (success && success.code && success.code === 200) {
          handleModalVisible(false);

          if (actionRef.current) {
            actionRef.current.reload();
          }
        }
      }}
    >
      <ProFormText
        width="md"
        name="id"
        disabled={true}
        label="id"
        hidden={true}
      />
      <ProFormGroup>
        <ProFormText
          width="md"
          rules={[
            {
              required: true,
              message: "医院名称为必填项",
            },
          ]}

          name="hosname"
          label="医院名称"
        />
        <ProFormText
          width="md"
          rules={[
            {
              required: true,
              message: "医院名称为必填项",
            },
          ]}
          label="医院编号"
          name="hoscode"/>
      </ProFormGroup>
      <ProFormGroup>
        <ProFormText
          width="md"
          name="contactsName"
          label="联系人姓名"
        />
        <ProFormText
          width="md"
          label="联系人手机号"
          name="contactsPhone"/>
      </ProFormGroup>
      <ProFormGroup>
        <ProFormText
          width="md"
          rules={[
            {
              required: true,
              message: "api基础路径为必填项",
            },
          ]}
          name="apiUrl"
          label="api基础路径"
        />
        <ProFormText
          width="md"
          label="signKey"
          name="signKey"/>
      </ProFormGroup>

      <ProFormGroup>
        <ProFormSelect
          width="md"
          rules={[
            {
              required: true,
              message: "状态为必选项",
            },
          ]}
          options={[
            {
              value: 1,
              label: '正常',
            }, {
              value: 0,
              label: '锁定',
            },
          ]}
          name="status"
          label="状态"
        />

      </ProFormGroup>

    </ModalForm>
  }
    return null



}

export default HospitalSetModalForm
